<?php

function tb_trser_market_admin_footer() {
	?>
	<script type="text/javascript">
	jQuery(document).ready(function(){
	//	jQuery('[id^=tb_trser_market_due_date]').datepicker({
	//		dateFormat : 'yy-mm-dd'
	//	});
	});
	</script>
	<?php
}

function tb_trser_market_footer() {
		?>
	<script type="text/javascript">
	jQuery(document).ready(function(){
		// create the error and highlight effects 							
		if($("div.error")[0]){
			createError($("div.error"));
		}
		
		if($("div.notice")[0]){
			createHighlight($("div.notice"));
		}		
		
		//functions start
		function createHighlight(obj){
			obj.addClass('ui-state-highlight ui-corner-all');
			obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
		}
		
		function createError(obj){
			obj.addClass('ui-state-error ui-corner-all');
			obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
		}
		
		
		// for each table cell color them 
		$('[id^=tb_trser_market_orders_no]').each(function() {
			// get table cell value and try to convert to an float
			var iValue = parseInt($(this).text());
			// if value is a number and less then zero
			if (!isNaN(iValue) && ((iValue%2)==0)) {
				// get table row
				var oTableRow = $(this).parent();
				// change the background color to red
				oTableRow.css('background-color', '#FCF7ED');
			}
		});
	});
	var _debug = false;
	var _placeholderSupport = function() {
		var t = document.createElement("input");
		t.type = "text";
		return (typeof t.placeholder !== "undefined");
	}();
	
	window.onload = function() {
		var arrInputs = document.getElementsByTagName("input");
		for (var i = 0; i < arrInputs.length; i++) {
			var curInput = arrInputs[i];
			if (!curInput.type || curInput.type == "" || curInput.type == "text" || curInput.type == "password")
				HandlePlaceholder(curInput);
		}
	};
	
	function HandlePlaceholder(oTextbox) {
		if (!_placeholderSupport) {
			var curPlaceholder = oTextbox.getAttribute("placeholder");
			if (curPlaceholder && curPlaceholder.length > 0) {
				Debug("Placeholder found for input box '" + oTextbox.name + "': " + curPlaceholder);
				oTextbox.value = curPlaceholder;
				oTextbox.setAttribute("old_color", oTextbox.style.color);
				oTextbox.setAttribute("old_type", oTextbox.type);
				oTextbox.style.color = "#c0c0c0";
				oTextbox.type = "text";
				oTextbox.onfocus = function() {
					Debug("input box '" + this.name + "' focus");
					this.style.color = this.getAttribute("old_color");
					this.type = this.getAttribute("old_type");
					if (this.value === curPlaceholder)
						this.value = "";
				};
				oTextbox.onblur = function() {
					Debug("input box '" + this.name + "' blur");
					if (this.value === "") {
						this.style.color = "#c0c0c0";
						oTextbox.type = "text";
						this.value = curPlaceholder;
					}
				};
			}
			else {
				Debug("input box '" + oTextbox.name + "' does not have placeholder attribute");
			}
		}
		else {
			Debug("browser has native support for placeholder");
		}
	}
	
	function Debug(msg) {
		if (typeof _debug !== "undefined" && _debug) {
			var oConsole = document.getElementById("Console");
			if (!oConsole) {
				oConsole = document.createElement("div");
				oConsole.id = "Console";
				document.body.appendChild(oConsole);
			}
			oConsole.innerHTML += msg + "<br />";
		}
	}
	</script>
	<?php
}
?>